#include<iostream>
#include"ezwin.h"
#include<cassert>
#include "rect.h"
#include<cmath>
using namespace std;
SimpleWindow W("Basic", 28.0, 21.5,
		      Position(1.0, 0.5));

struct Range{
	float l;
	float u;
}R[4];


int ApiMain() {
	int i,z;
	int j;
	W.Open();
	float y[4],ymax=18.0,xmax=20.0,xdiv=1.0,ydiv=1.0,midpoint[4];
	cout<<"enter 4 ranges for histogram : "<<endl;
	for(i=0;i<4;i++)
	{
		cin>>R[i].l;
		cin>>R[i].u;
		midpoint[i]=(R[i].l+R[i].u)/2;		
	}

	cout<<"Enter corresponding frequencies : ";
	
	for(i=0;i<4;i++)
		cin>>y[i];
	
	for(i=0;i<4;i++)
	{
		if(xmax<R[i].u)
			xmax=R[i].u;
		if(ymax<y[i])
			ymax=y[i];
	}

	z=xmax/10;		
	xmax=(z+1)*10;

	z=ymax/10;		
	ymax=(z+1)*10;

	xdiv=xdiv*xmax/20.0;
	ydiv=ydiv*ymax/18.0;	

	W.RenderLine(Position(2.0,0.5),Position(2.0,20.0),Black,0.05);		//Y-axis
	W.RenderLine(Position(2.0,0.5),Position(1.8,1.0),Black,0.05);	//Arrow
	W.RenderLine(Position(2.0,0.5),Position(2.2,1.0),Black,0.05);	//Arrow
	W.RenderLine(Position(2.0,20.0),Position(23.5,20.0),Black,0.05);	//X-axis
	W.RenderLine(Position(23.0,19.8),Position(23.5,20.0),Black,0.05);	//Arrow
	W.RenderLine(Position(23.0,20.2),Position(23.5,20.0),Black,0.05);	//Arrow

	for(j=1.0; j<=18.0; j++)
	{
		W.RenderLine(Position(1.9,20.0-j),Position(2.1,20.0-j),Black,0.05);	//Markings on Y-axis
//		W.RenderText(Position(1.8,19.8-j),Position(2.2,20.2-j),s,Red);
	}
	for(j=3.0; j<=22.0; j++)
		W.RenderLine(Position(j,19.9),Position(j,20.1),Black,0.05);	//Markings on X-axis

	for(j=0; j<4; j++)
	{
		W.RenderRectangle(Position(R[j].l/xdiv+2.0,20.0-y[j]/ydiv), Position(R[j].u/xdiv+2.0,20.0),Cyan,true); 
		W.RenderLine(Position(midpoint[j]/xdiv+2.0,20.0-y[j]/ydiv), Position(midpoint[j]/xdiv+2.0,20.0-y[j]/ydiv), Red, 0.15);
	}
	for(j=0;j<3;j++)
		W.RenderLine(Position(midpoint[j]/xdiv+2.0,20.0-y[j]/ydiv), Position(midpoint[j+1]/xdiv+2.0,20.0-y[j+1]/ydiv), Red, 0.05);
	
	
/*
	for(i=0;i<3;i++)
	{
		W.RenderLine(Position(x[i]*xdiv+2.0,20.0-(y[i]*ydiv)),Position(2.0,20.0-(y[i]*ydiv)),Magenta,0.0);	//Projections
		W.RenderLine(Position(x[i]*xdiv+2.0,20.0-(y[i]*ydiv)),Position(x[i]*xdiv+2.0,20.0),Magenta,0.0);	//Projections
	}
	W.RenderLine(Position(x[i]*xdiv+2.0,20.0-(y[i]*ydiv)),Position(2.0,20.0-(y[i]*ydiv)),Magenta,0.0);	//Projection of last point
	W.RenderLine(Position(x[i]*xdiv+2.0,20.0-(y[i]*ydiv)),Position(x[i]*xdiv+2.0,20.0),Magenta,0.0);	//Projection of last point
	
	for(i=0;i<3;i++)
	{
		W.RenderLine(Position(x[i]*xdiv+2.0,20.0-(y[i]*ydiv)),Position(x[i]*xdiv+2.0,20.0-(y[i]*ydiv)),Red,0.2);	//Coordinates	
		W.RenderLine(Position(x[i]*xdiv+2.0,20.0-(y[i]*ydiv)),Position((x[i+1]*xdiv+2.0),20.0-(y[i+1]*ydiv)),Red,0.0);	//Histogram lines
	}
	W.RenderLine(Position(x[i]*xdiv+2.0,20.0-(y[i]*ydiv)),Position(x[i]*xdiv+2.0,20.0-(y[i]*ydiv)),Red,0.2);
*/
	return 0;
}

